string = 'JagochanJack'

# 1、通过索引获取字符串中的某个字符
char1 = string[5]
char2 = string[-7]
print(char1 == char2)  # True
print(char1, char2)
# TypeError: 'str' object does not support item assignment
# string[5] = 'H'
print('🍀🍀🍀🍀🍀🍀')

# 2、index方法
index = string.index('anJ')
print(index == 6)
print('🍀🍀🍀🍀🍀🍀')

# 3、字符串的替换
newString = string.replace('a', 'A')
print(F'newString: {newString}')
print('🍀🍀🍀🍀🍀🍀')

# 4、字符串的分割
string1 = 'apple, banana, safe, happy, money, rich, healthy, great'
split_list = string1.split(', ')
print(len(split_list) == 8)
print(split_list, type(split_list))
for item in split_list:
    print(F'分割item: {item}')
print('🍀🍀🍀🍀🍀🍀')

# 5、strip方法
phone = '  \t 16686667888  \n'
print(F'strip操作之前：【{phone}】')
newPhone = phone.strip()
print(F'strip操作之后：【{newPhone}】')

string2 = 'success666success888success'
print(F'strip操作之前：【{string2}】')
newString2 = string2.strip('success')
print(F'strip操作之后：【{newString2}】')
print('🍀🍀🍀🍀🍀🍀')

# 6、统计字符串子串出现的次数
print(string2.count('success') == 3)

# 7、统计字符串的长度
print(len(string2))
print('🍀🍀🍀🍀🍀🍀')

# 8、字符串的遍历
name = 'Jagochan'
# while循环遍历
i = 0
while i < len(name):
    print(F'while: {name[i]}')
    i += 1
print('🍀🍀🍀🍀🍀🍀')

# for循环遍历
for char in name:
    print(F'for: {char}')
